Repository navigation
perf(deletion-vector): avoid payload copies and bitmap reserialization - #4181
Merged
kevinjqliu merged 3 commits intoNov 13, 2026
Merged
kevinjqliu merged 3 commits into
kevinjqliu merged 3 commits into
Conversation
Replace repeated byte string slicing with pointer offset tracking via Python's built-in memoryview. This avoids O(N^2) memory buffer allocations during parsing, improving throughput by up to 39x on large payload sizes.
ArslanAnjum
marked this pull request as ready for review
October 29, 2026 18:56
Use PyRoaring's portable serialized size and require memoryview-compatible versions. Cover mixed bitmap encodings and key gaps without reserialization. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kevinjqliu
approved these changes
Nov 13, 2026
kevinjqliu
left a comment
Contributor
There was a problem hiding this comment.
LGTM! nice optimization
i cleaned up the code and pr description.
pyroaring needs >= 1.1 to use memoryview so i bump the version
| number_of_bitmaps = int.from_bytes(pl[0:8], byteorder="little") | ||
| pl = pl[8:] | ||
| def _deserialize_bitmap(payload: bytes) -> list[BitMap]: | ||
| payload_view = memoryview(payload) |
Contributor
There was a problem hiding this comment.
Using memoryview is the main optimization here: it lets us advance through the payload without repeatedly copying the remaining bytes.
| bitmaps.append(bm) | ||
| bitmap = BitMap.deserialize(payload_view[offset:]) | ||
| # PyRoaring's __sizeof__ returns the portable serialized size without allocating bytes. | ||
| offset += bitmap.__sizeof__() |
Contributor
There was a problem hiding this comment.
another optimization: __sizeof__() uses the same size calculation as serialize(), without allocating or serializing bytes.
| "pyparsing>=3.1.0", | ||
| "tenacity>=8.2.3", | ||
| "pyroaring>=1.0.0", | ||
| "pyroaring>=1.1.0", |
Contributor
There was a problem hiding this comment.
Requires PyRoaring ≥1.1.0 for memoryview support; see the updated deserialize() signature.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
Repeatedly slicing the remaining deletion-vector payload copies data for every bitmap. Use a memoryview and an offset to avoid those copies, and advance using PyRoaring's portable serialized size (
__sizeof__()) instead of serializing each decoded bitmap again.Require PyRoaring >=1.1.0, which accepts memoryview input. Keep byte widths explicit and cover mixed bitmap containers, missing keys, and parsing without reserialization.
Local synthetic benchmarks using the original description's generators, PyRoaring 1.1.0, and median timings across five repeated timeit batches show the additional improvement over the memoryview-only implementation:
These are local microbenchmark results, not end-to-end query speedups. Input slicing is zero-copy; bitmap deserialization still allocates decoded bitmaps.
Are these changes tested?
make lint— passed.uv run --no-sync python -m pytest -m unit tests/table/test_deletion_vector.py -q— 13 passed with PyRoaring 1.1.0.uv run --no-sync --default-index https://pypi.org/simple --with pyroaring==1.2.0 python -m pytest -m unit tests/table/test_deletion_vector.py -q— 13 passed with PyRoaring 1.2.0.make test— blocked during collection because the optional Hive dependencythriftis missing locally.Are there any user-facing changes?
No intended changes to decoded row positions or public APIs. The minimum PyRoaring version increases from 1.0.0 to 1.1.0.